/**
 * 功能:发布新微博
 * 创建日期: 2012-03-16
 * 创建人: 全轩
 * 功能修正说明:
 * 		1
 */
if(!this.UpdateStatuses)
{
	this.UpdateStatuses = {};
}
(function(){
	if(!UpdateStatuses.Win)
	{
		UpdateStatuses.Win = Ti.UI.createWindow({
			title:'发表新的微博',
		});
	}
	
	if(!UpdateStatuses.Content)
	{
		UpdateStatuses.Content = '';
	}
	
	if(!UpdateStatuses.Img)
	{
		UpdateStatuses.Img = null;
	}
	
	if(typeof UpdateStatuses.start !== 'function')
	{
		UpdateStatuses.start = function(parentWin)
		{
			var send = Titanium.UI.createButton({
			    title : 'Send',
			    style : Titanium.UI.iPhone.SystemButtonStyle.DONE,
			});
			
			send.addEventListener('click',function(e){
				UpdateStatusesHandler.Publish(e,function(newstatues){
					//发布新的微博成功后,并且已经获取到新微博的相关数据
					
				});
			});
			 
			var camera = Titanium.UI.createButton({
			    systemButton : Titanium.UI.iPhone.SystemButton.CAMERA,
			});
			camera.addEventListener('click',function(){
				Titanium.Media.showCamera
				({
					success:function(event)
					{
						updatestatuses.Img = event.media;
					},
					cancel:function()
					{
					},
					error:function(error)
					{
					},
					showControls:true, 
					mediaTypes:Ti.Media.MEDIA_TYPE_PHOTO,
					autohide:true,
					transform: Titanium.UI.create2DMatrix().scale(2,2)  
				});
			});
			 
			var cancel = Titanium.UI.createButton({
			    systemButton : Titanium.UI.iPhone.SystemButton.CANCEL
			});
			 
			var flexSpace = Titanium.UI.createButton({
			    systemButton : Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE
			});
 
 			var lbtypecount = Ti.UI.createLabel({
 				text : '140字',
			    style : Titanium.UI.iPhone.SystemButtonStyle.DONE,
 			});
			
			var browserfile = Titanium.UI.createButton({
				title:'broswer',
			    style : Titanium.UI.iPhone.SystemButtonStyle.DONE
			});
			browserfile.addEventListener('click',function(e){
				Ti.Media.openPhotoGallery({
						success:function(event)
						{
							if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
							{
								UpdateStatuses.Img = event.media;
							}
						},
						cancel:function(){
							
						},
						error:function()
						{
							
						},
						allowEditing:true,
						medialTypes:[Ti.Media.MEDIA_TYPE_PHOTO,Ti.Media.MEDIA_TYPE_VIDEO]
					});
			});
			
			var textarea = Ti.UI.createTextArea({
				width:'100%',
				height:'200px',
				top:'1px',
				font : {fontSize:20,fontFamily:'Marker Felt', fontWeight:'bold'},
			    color : '#888',
			    textAlign : 'left',
			    appearance : Titanium.UI.KEYBOARD_APPEARANCE_ALERT, 
			    keyboardType : Titanium.UI.KEYBOARD_NUMBERS_PUNCTUATION,
			    returnKeyType : Titanium.UI.RETURNKEY_EMERGENCY_CALL,
			    borderWidth : 2,
			    borderColor : '#bbb',
			    borderRadius : 5,
			    keyboardToolbar : [cancel, flexSpace,browserfile, flexSpace,camera, flexSpace,lbtypecount,flexSpace, send],
			    keyboardToolbarColor : '#999',
			    keyboardToolbarHeight : 40,
			});
			
			textarea.addEventListener('change',function(){
				UpdateStatuses.Content = this.value;
				lbtypecount.text = (140 - UpdateStatuses.Content.length) + '字';
			});
			
			UpdateStatuses.Win.add(textarea);
			
			if(parentWin != null && parentWin != undefined)
			{
				UpdateStatuses.ParentWin = parentWin;
			}
			
			UpdateStatuses.Win.open();
		}
	}
}())